package com.yihu.wlyy.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.yihu.wlyy.entity.WlyyTalkGroup;

public interface TalkGroupDao extends PagingAndSortingRepository<WlyyTalkGroup, Long>{
	
	/**
	 * 查询医生对应讨论组
	 * 
	 * @param doctor
	 * @return
	 */
	@Query("select tg from WlyyTalkGroup tg, WlyyTalkGroupMember tgm where tg.code = tgm.groupCode and tgm.memberCode = ?1")
	List<WlyyTalkGroup> findDoctorTalkGroups(String doctor);

	@Query("select tg from WlyyTalkGroup tg,WlyyTalkGroupMember tgm where tg.code = tgm.groupCode and tgm.memberName like ?1 and tg.code in (?2)")
	List<WlyyTalkGroup> findByDoctorName(String doctorName,String groupCode);
	
	/**
	 * 根据咨询查询讨论组
	 * 
	 * @param consultCode
	 * @return
	 */
	WlyyTalkGroup findByConsultCode(String consultCode);
	
	/**
	 * 获取医生对应病人讨论组
	 * 
	 * @param doctor
	 * @param patient
	 * @return
	 */
	@Query("select tg from WlyyTalkGroup tg,WlyyTalkGroupMember tgm where tg.code = tgm.groupCode and tgm.memberCode = ?1 and tg.patient = ?2")
	List<WlyyTalkGroup> findByDoctorAndPatient(String doctor,String patient);
	
	WlyyTalkGroup findByCode(String code);
}
